<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	<meta charset="UTF-8">
	<title>库存录入</title>
	<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no' name='viewport' />
	<link rel="stylesheet" href="assets/css/bootstrap.min.css">
	<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i">
	<link rel="stylesheet" href="assets/css/ready.css">
</head>
<body>
<div class="wrapper">
	<div class="main-header">
		<div class="logo-header">
			<a href="enterProduct.html" class="logo">
				艾尔之光仓库管理
			</a>
			<button class="navbar-toggler sidenav-toggler ml-auto" type="button" data-toggle="collapse" data-target="collapse" aria-controls="sidebar" aria-expanded="false" aria-label="Toggle navigation">
				<span class="navbar-toggler-icon"></span>
			</button>
			<button class="topbar-toggler more"><i class="la la-ellipsis-v"></i></button>
		</div>
	</div>
	<div class="sidebar">
		<div class="scrollbar-inner sidebar-wrapper">
			<ul class="nav">
				<li class="nav-item">
					<a href="enterProduct.html">
						<i class="la la-th"></i>
						<p>商品录入</p>
					</a>
				</li>
				<li class="nav-item active">
					<a href="enterInventory.html">
						<i class="la la-th"></i>
						<p>库存录入</p>
					</a>
				</li>
				<li class="nav-item">
					<a href="enterPurchase.html">
						<i class="la la-th"></i>
						<p>采购预录</p>
					</a>
				</li>
				<li class="nav-item">
					<a href="enterGoodsArrived.html">
						<i class="la la-th"></i>
						<p>采购到货录入</p>
					</a>
				</li>
				<li class="nav-item">
					<a href="export.html">
						<i class="la la-th"></i>
						<p>导出Execl</p>
					</a>
				</li>
				<li class="nav-item">
					<a href="updateSalesperson.html">
						<i class="la la-th"></i>
						<p>修改业务员姓名</p>
					</a>
				</li>
			</ul>
		</div>
	</div>
	<div class="main-panel">
		<div class="content">
			<div class="container-fluid">
				<div class="card">
					<div class="card-header">
						<div class="card-title">库存录入</div>
					</div>
					<div class="card-body">
						<div class="form-group form-inline">
							<label for="modelName" class="col-md-3 col-form-label">型号</label>
							<div class="col-md-9 p-0">
								<input type="text" class="form-control input-full" id="modelName" placeholder="请输入商品型号">
							</div>
						</div>
						<div class="form-group form-inline">
							<label for="modelName" class="col-md-3 col-form-label">型号2</label>
							<div class="col-md-9 p-0">
								<input type="text" class="form-control input-full" id="sku" placeholder="请输入型号2">
							</div>
						</div>
						<div class="form-group form-inline">
							<label for="salesperson" class="col-md-3 col-form-label">业务员</label>
							<div class="col-md-9 p-0">
								<input type="text" list="salespersonList" class="form-control input-full" id="salesperson" placeholder="请输入业务员姓名">
								<datalist id="salespersonList">

								</datalist>
							</div>
						</div>
						<div class="form-group form-inline">
							<label for="inventoryQuantity" class="col-md-3 col-form-label">现有库存数量</label>
							<div class="col-md-9 p-0">
								<input type="text" class="form-control input-full" id="inventoryQuantity" placeholder="请输入库存数量">
							</div>
						</div>
					</div>
					<div id="enterInventory" class="card-action">
						<button class="btn btn-success">录入</button>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<script src="assets/js/core/jquery.3.2.1.min.js"></script>
<script src="assets/js/plugin/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>
<script src="assets/js/core/popper.min.js"></script>
<script src="assets/js/core/bootstrap.min.js"></script>
<script src="assets/js/plugin/chartist/chartist.min.js"></script>
<script src="assets/js/plugin/chartist/plugin/chartist-plugin-tooltip.min.js"></script>
<script src="assets/js/plugin/bootstrap-notify/bootstrap-notify.min.js"></script>
<script src="assets/js/plugin/bootstrap-toggle/bootstrap-toggle.min.js"></script>
<script src="assets/js/plugin/jquery-mapael/jquery.mapael.min.js"></script>
<script src="assets/js/plugin/jquery-mapael/maps/world_countries.min.js"></script>
<script src="assets/js/plugin/chart-circle/circles.min.js"></script>
<script src="assets/js/plugin/jquery-scrollbar/jquery.scrollbar.min.js"></script>
<script src="assets/js/ready.min.js"></script>
<script>
	//库存录入功能
	$("#enterInventory").click(function (){
		var modelName = $("#modelName").val();
		var salesperson = $("#salesperson").val();
		var inventoryQuantity = parseInt($("#inventoryQuantity").val());
		var sku = $("#sku").val();
		var json = {
			"modelName":modelName,
			"salesperson":salesperson,
			"inventoryQuantity":inventoryQuantity,
			"sku":sku
		};
		console.log(json)
		if (!modelName){
			alert("请输入型号");
			throw new Error("型号输入异常");
		}
		if (!sku){
			alert("请输入型号2");
			throw new Error("型号2输入异常");
		}
		if (!salesperson){
			alert("请输入业务员名字");
			throw new Error("业务员名字输入异常");
		}
		if (inventoryQuantity<0){
			alert("请输入合法的库存数量");
			throw new Error("库存数量输入异常");
		}
		json = JSON.stringify(json)//转化为json字符串
		$.ajax({
			url: "/enter_inventory",
			headers:{
				'Content-Type': 'application/json' // 确保这里的 Content-Type 与服务器端期望的格式一致
			},
			type: 'post',
			data: json,
			async: false,   //如果不加，无法实现数据传值
			dataType: 'json',
			success: function (datajson) {
				console.log(datajson)
				alert(datajson["message"])
			},
			error: function (){
				alert("录入失败")
			}
		});
	});



	// 获取所有业务员列表
	$.ajax({
		url: "/get_all_salesperson",
		type: 'post',
		async: false,   //如果不加，无法实现数据传值
		dataType: 'json',
		success: function (datajson) {
			var result = datajson;
			console.log(result);
			if (result.code == "0000"){
				var data = result.data
				$(data).each(function (key) {  //循环读取后台传来的Json数据
					AppendSalespersonNode(data[key], data[key]);   //将value和text添加到下拉框中
				});
			}else {
				alert(result.message)
			}
		},
		error: function () {
			alert("出现错误");
		}
	});
	function AppendSalespersonNode(value, text) {
		$("#salespersonList").append("<option value='" + value + "'>" + text + "</option>");
	}
</script>
</html>